﻿// https://learn.microsoft.com/zh-cn/typography/opentype
// language id: https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f
using System;

namespace tuimg.structs
{
    internal struct struct_ttf_head
    {
        internal uint sfntVersion; // 文件类型
        internal ushort numTables; // 表数量
        internal ushort searchRange; //Maximum power of 2 less than or equal to numTables, times 16 ((2**floor(log2(numTables))) * 16, where “**” is an exponentiation operator).
        internal ushort entrySelector; //Log2 of the maximum power of 2 less than or equal to numTables (log2(searchRange/16), which is equal to floor(log2(numTables))).
        internal ushort rangeShift; //	numTables times 16, minus searchRange ((numTables * 16) - searchRange).
    }

    internal struct struct_ttf_table_record
    {
        internal string tableTag; // Table identifier.
        internal uint checksum; // Checksum for this table.
        internal uint offset; // Offset from beginning of font file.
        internal uint length; // Length of this table.
    }

    internal struct struct_ttf_name_v0
    {
        internal ushort version; // Table version number (=0).
        internal ushort count; // Number of name records.
        internal ushort storageOffset; // Offset to start of string storage (from start of table).
        internal struct_ttf_name_record[] nameRecords;
    }
    internal struct struct_ttf_name_v1
    {
        internal ushort version; // Table version number (=1).
        internal ushort count; // Number of name records.
        internal ushort storageOffset; // Offset to start of string storage (from start of table).
        internal struct_ttf_name_record[] nameRecords;
        internal ushort langTagCount; // Number of language-tag records.
        internal struct_ttf_name_langtag[] langTagRecords;
    }
    internal struct struct_ttf_name_langtag
    {
        internal ushort length; // Language-tag string length (in bytes).
        internal ushort langTagOffset; // Language-tag string offset from start of storage area (in bytes).
    }
    internal struct struct_ttf_name_record
    {
        internal ushort platformID; // Platform ID.
        internal ushort encodingID; // 	Platform-specific encoding ID.
        internal ushort languageID; // Language ID.
        internal ushort nameID; // 	Name ID.
        internal ushort length; // String length (in bytes).
        internal ushort stringOffset; // String offset from start of storage area (in bytes).
    }
    internal struct struct_ttf_cmap_head
    {
        internal ushort version; // Table version number (0).
        internal ushort numTables; // Number of encoding tables that follow.
        internal struct_ttf_cmap_encoding_record[] encodingRecords;
        internal object[] encodingTables;
    }
    internal struct struct_ttf_cmap_encoding_record
    {
        internal ushort platformID; // 	Platform ID.
        internal ushort encodingID; // Platform-specific encoding ID. platformSpecificID 
        internal uint subtableOffset; // 	Byte offset from beginning of table to the subtable for this encoding.
    }
    internal struct struct_ttf_cmap_encoding_table_f0
    {
        internal ushort format;
        internal ushort length;
        internal ushort language;
    }
    internal struct struct_ttf_cmap_encoding_table_f4
    {
        internal ushort format;
        internal ushort length;
        internal ushort language;
        internal ushort segCountX2;
        internal ushort segCount;
        internal ushort searchRange;
        internal ushort entrySelector;
        internal ushort rangeShift;
        internal ushort[] endCode;
        internal ushort reservedPad;
        internal ushort[] startCode;
        internal short[] idDelta;
        internal ushort[] idRangeOffset;
        internal long glyphIdOffset;
        internal ushort[] glyphIdArray;
    }
    internal struct struct_ttf_maxp_v0_5
    {
        internal decimal version;
        internal ushort numGlyphs;
    }
    internal struct struct_ttf_maxp_v1_0
    {
        internal decimal version;
        internal ushort numGlyphs;
        internal ushort maxPoints;
        internal ushort maxContours;
        internal ushort maxCompositePoints;
        internal ushort maxCompositeContours;
        internal ushort maxZones;
        internal ushort maxTwilightPoints;
        internal ushort maxStorage;
        internal ushort maxFunctionDefs;
        internal ushort maxInstructionDefs;
        internal ushort maxStackElements;
        internal ushort maxSizeOfInstructions;
        internal ushort maxComponentElements;
        internal ushort maxComponentDepth;
    }
    internal struct struct_ttf_loca
    {
        internal uint length;
        internal uint[] offsets;
    }
    internal struct struct_ttf_glyf_head
    {
        internal int PtsCount;
        internal short numberOfContours;
        internal short xMin;
        internal short yMin;
        internal short xMax;
        internal short yMax;
        internal ushort[] endPtsOfContours; // 每个轮廓最后一个点的点索引数组，按数值递增顺序排列。
        internal ushort instructionLength;
        internal byte[] instructions;
        internal byte[] flags;
        internal short[] xCoordinates;
        internal short[] yCoordinates;

        internal struct_ttf_glyf_component[] components;// when numberOfContours < 0
    }
    internal struct struct_ttf_glyf_component
    {
        internal decimal xscale;
        internal decimal yscale;
        internal decimal scale01;
        internal decimal scale10;
        internal ushort flags;
        internal ushort glyphIndex;
        internal ushort argument1;
        internal ushort argument2;
        internal ushort xtranslate;
        internal ushort ytranslate;
        internal ushort point1;
        internal ushort point2;
    }
    internal struct struct_ttf_head_info
    {
        internal ushort majorVersion;
        internal ushort minorVersion;
        internal uint fontRevision;
        internal uint checksumAdjustment;
        internal uint magicNumber;
        internal ushort flags;
        internal ushort unitsPerEm;
        internal ulong created;
        internal ulong modified;
        internal short xMin;
        internal short yMin;
        internal short xMax;
        internal short yMax;
        internal ushort macStyle;
        internal ushort lowestRecPPEM;
        internal short fontDirectionHint;
        internal short indexToLocFormat;
        internal short glyphDataFormat;
    }
    internal struct struct_ttf_hhea
    {
        internal uint version;
        internal short ascender;
        internal short descender;
        internal short lineGap;

        internal ushort advanceWidthMax;
		internal short minLeftSideBearing;
		internal short minRightSideBearing;
		internal short xMaxExtent;
		internal short caretSlopeRise;
		internal short caretSlopeRun;
		internal short reserved1;
		internal short reserved2;
		internal short reserved3;
		internal short reserved4;
		internal short reserved5;
		internal short metricDataFormat;
		internal ushort numberOfHMetrics;
    }
    internal enum struct_ttf_cmap_platform_id0 : ushort
    {
        Unicode = 0,
        Macintosh =1,
        ISO = 2,
        Windows = 3,
        Custom = 4,
    }
    internal enum enum_ttf_platform_ids : ushort
    {
        Unicode = 0,
        Macintosh = 1,
        Windows = 3,
    }
    internal enum enum_ttf_platform_0_encoding_ids : ushort
    {
        Unicode_1_0 = 0,
        Unicode_1_1 = 1,
        ISO_or_IEC_10646 =2,
        Unicode_2_0_BMP = 3,
        Unicode_2_0 = 4,

    }
    internal enum enum_ttf_platform_1_encoding_ids : ushort
    {
        Roman =0,
        Japanese =1,
        Chinese_Traditional = 2,
        Korean = 3,
        Arabic =4,
        Hebrew = 5,
        Greek = 6,
        Russian = 7,
        RSymbol = 8,
        Devanagari = 9,
        Gurmukhi = 10,
        Gujarati = 11,
        Odia = 12,
        Bangla = 13,
        Tamil = 14,
        Telugu = 15,
        Kannada = 16,
        Malayalam = 17,
        Sinhalese = 18,
        Burmese = 19,
        Khmer = 20,
        Thai = 21,
        Laotian = 22,
        Georgian = 23,
        Armenian = 24,
        Chinese_Simplified = 25,
        Tibetan = 26,
        Mongolian = 27,
        Geez = 28,
        Slavic = 29,
        Vietnamese = 30,
        Sindhi = 31,
        Uninterpreted = 32,
    }
    internal enum enum_ttf_platform_3_encoding_ids : ushort
    {
        Symbol = 0,
        Unicode_BMP = 1,
        ShiftJIS = 2,
        PRC = 3,
        Big5 = 4,
        Wansung = 5,
        Johab = 6,
        Reserved_7 = 7,
        Reserved_8 = 8,
        Reserved_9 = 9,
        Unicode_full_repertoire = 10,

    }
    internal enum enum_ttf_names : ushort
    {
        Copyright_notice = 0,
        Font_Family_name = 1,
        Font_Subfamily_name = 2,
        Unique_font_identifier = 3,
        Full_font_name = 4,
        Version = 5,
        PostScript_name = 6,
        Trademark = 7,
        Manufacturer_Name = 8,
        Designer_Name = 9,
        Description = 10,
        URL_of_Vendor = 11,
        URL_of_Designer = 12,
        License_Description = 13,
        License_Info_URL = 14,
        Reserved = 15,
        Typographic_Family_name = 16,
        Typographic_Subfamily_name = 17,
        Compatible_Full = 18,
        Sample_text = 19,
        PostScript_CID_findfont_name = 20,
        WWS_Family_Name = 21,
        WWS_Subfamily_Name = 22,
        Light_Background_Palette = 23,
        Dark_Background_Palette = 24,
        Variations_PostScript_Name_Prefix = 25
    }

}
